<extend name="common:commonNewerTemplate" />
<block name="main_content">
<div id="content">
	<div id="content-header">
		<div id="breadcrumb">
			<a class="tip-bottom" href="index.html"
				data-original-title="Go to Home"><i class="icon-home"></i> 首页</a>
			<a href="#">经销商</a> <a class="current" href="#">经销商账户后返余额列表</a>
		</div>
		
	</div>
	<div class="container-fluid">
		<div class="row-fluid">
			<div class="span6">
				<div class="widget-box">
					<div class="widget-title">
						<span class="icon"> <i class="icon-info-sign"></i>
						</span>
						<h5>搜索条件（仅支持搜索单用户）</h5>
					</div>
					<div class="widget-content nopadding">
						<form novalidate="novalidate" id="basic_validate"
							name="basic_validate" action="#" method="post"
							class="form-horizontal">
							<div class="control-group">
								<label class="control-label">经销商编号:</label>
								<div class="controls">
									<input type="text" id="dealer_id" name="dealer_id" placeholder="推荐搜索条件"/>
								</div>
							</div>
							<div class="control-group">
								<label class="control-label">变更种类：</label>
								<div class="controls">
								<select id="amount_type" name="amount_type" style="width:220px;" >
									<option value="">--ALL--</option>
									<option value="11">管理员增加</option>
									<option value="12">订单提成</option>	
									<option value="13">充值</option>
									<option value="15">订单取消余额退回</option>
									<option value="16">退货退款</option>
									<option value="21">管理员减少</option>	
									<option value="22">提现</option>
									<option value="24">订单支付</option>							
								</select>
								</div>
							</div>
							<div class="control-group">
								<label class="control-label">日期：</label>
								<div class="controls">
									<!-- <input id="start_date" class="laydate-icon" onclick="laydate()" readonly>-
									<input id="end_date" class="laydate-icon" onclick="laydate()" readonly> -->
									<input id="start_date" name="start_date" style="background-color: #fff;border: 1px solid #ccc;box-shadow: 0 1px 1px rgba(0, 0, 0, 0.075) inset;width:217px;color:#555;transition: border 0.2s linear 0s, box-shadow 0.2s linear 0s;" onclick="laydate({istime: true, format: 'YYYY-MM-DD hh:mm:ss'})">-
									<input id="end_date" name="end_date" style="background-color: #fff;border: 1px solid #ccc;box-shadow: 0 1px 1px rgba(0, 0, 0, 0.075) inset;width:217px;color:#555;transition: border 0.2s linear 0s, box-shadow 0.2s linear 0s;" onclick="laydate({istime: true, format: 'YYYY-MM-DD hh:mm:ss'})">
								</div>
							</div>
							<div class="form-actions">
								<input id="btn_search" type="button" class="btn btn-success"  onclick="DealerCashBackAmountPage.searchclick();" value="搜索">
							</div>
						</form>
					</div>
				</div>
			</div>
			<div class="span6">
				<div class="widget-box">
					<div class="widget-title">
						<span class="icon"> <i class="icon-info-sign"></i>
						</span>
						<h5>余额变更</h5>
					</div>
					<div class="widget-content nopadding">
						<form novalidate="novalidate" id="basic_validate1"
							name="basic_validate1" action="#" method="post"
							class="form-horizontal">
							<div class="control-group">
								<label class="control-label">经销商编号:</label>
								<div class="controls">
									<input type="text" id="dealer_id1" name="dealer_id" placeholder="推荐输入条件"/>
								</div>
							</div>
							<div class="control-group">
								<label class="control-label">变更类型:</label>
								<div class="controls">
									<select style="width:220px;" name="amount_type" id="amount_type">
					                  <option value="11">管理员增加</option>
					                  <option value="21">管理员减少</option>
					                </select>
								</div>
							</div>
							<div class="control-group">
								<label class="control-label">金额:</label>
								<div class="controls">
									<input type="text" id="amount" name="amount" placeholder="输入大于的0的金额"/>
								</div>
							</div>
							<div class="control-group">
								<label class="control-label">备注:</label>
								<div class="controls">
									<input type="text" id="remark" name="remark" placeholder=""/>
								</div>
							</div>
							<div class="form-actions">
								<input id="btn_updateAmount" type="button" class="btn btn-danger" onclick="DealerCashBackAmountPage.AmountUpdate();" value="变更">
							</div>
						</form>
					</div>
				</div>
			</div>
		</div>
	
		<div class="row-fluid">
      <div class="span12">
        <div class="widget-box">
          <div class="widget-title"> <span class="icon"> <i class="icon-th"></i> </span>
            <h5>搜索结果</h5>
             <span style="float:right;margin:3px;">
				<a href="#" class="btn btn-primary" id="exportXls">导出经销商后返余额xls</a>
			</span>
          </div>
          <div class="widget-content nopadding">
            <table id="search_result"  class="table table-bordered table-striped">
              <thead>
                <tr>
                  <th>经销商编号</th>
                  <th>经销商名称</th>
                  <th>变动种类</th>
                  <th>变动类型</th>
                  <th>变动前金额</th>
                  <th>变动金额</th>
                  <th>变动后金额</th>
                  <th>相关订单编号</th>
                  <th>备注</th>
                  <th>操作时间</th>
                </tr>
              </thead>
              <tbody>
              </tbody>
            </table>
          </div>
      </div>
      <div id="paging"
                         class="fg-toolbar ui-toolbar ui-widget-header ui-corner-bl ui-corner-br ui-helper-clearfix">
                        <div class="dataTables_paginate fg-buttonset ui-buttonset fg-buttonset-multi ui-buttonset-multi paging_full_numbers"
                             id="DataTables_Table_0_paginate">
                            <a page_index="1"
                               class="first ui-corner-tl ui-corner-bl fg-button ui-button ui-state-default" tabindex="0"
                               id="DataTables_Table_0_first">首页</a>
                            <a class="previous fg-button ui-button ui-state-default" tabindex="0"
                               id="DataTables_Table_0_previous">上页</a>
                            <span>共<span id="total_count">0</span>条 <span id="curr_page_index">0</span>/<span
                                    id="total_page">0</span></span>
                            <a class="next fg-button ui-button ui-state-default" tabindex="0"
                               id="DataTables_Table_0_next">下页</a>
                            <a class="last ui-corner-tr ui-corner-br fg-button ui-button ui-state-default" tabindex="0"
                               id="DataTables_Table_0_last">末页</a>
       			<span>
        			<span><input type="text" id="page_input" style="width:20px;" class="ui-state-default"></span>

        			<a class="fg-button ui-button ui-state-default" id="page_jump" tabindex="0">跳转</a>
       			</span>
                        </div>
       </div>
    </div>
  </div>


</div>
</div>
</block>

<block name="js_content">
<script src="../../../Public/js/laydate/laydate.js"></script>
<script>
DealerCashBackAmountPage = {
		
		
		'searchclick':function(){
			
			
			DealerCashBackAmountPage.Search(1);

		},
		
		'BindEvent': function(){
			/* $('#btn_dealer_search').bind('click', function(){
				
				 
				 var page_index = 1;
				 DealerCashBackAmountPage.Search(page_index);
			}); */
			
			$('#exportXls').on('click',function(){
				
				
				var startdate	= $('#start_date').val();
				var enddate	= $('#end_date').val();
				
					if(startdate ==""){
						alert("开始日期不能为空！！！");
						return ;
					}
				   			
					if(enddate ==""){
						alert("结束日期不能为空！！！");
						return ;
					}
					
					var startdates = startdate.split('-');
					var enddates = enddate.split('-');

					startdate = startdates[1] + '/' + startdates[2].split(" ")[0] + '/' + startdates[0]+" "+startdates[2].split(" ")[1] ;
							
					enddate = enddates[1] + '/' + enddates[2].split(" ")[0] + '/' + enddates[0]+" " +enddates[2].split(" ")[1];
                    //alert(startdates);
					//alert(startdate);
					
					// MM/dd/yyyy HH:mm:ss
					// alert(Date.parse(startdate));
					 //alert(Date.parse(enddate));
					 
					// var b = (Date.parse(enddate) - Date.parse(startdate)) / ( 3600 * 1000);
					// alert(b);
					 var a = Date.parse(enddate) - Date.parse(startdate) ;
					
					 if(a < 0){
							alert("结束时间不能早于开始时间,请检查!");
							return ;
						}else{
							 a = a/(24*3600*1000.0);
							if(a >60){
								
								alert("只能导出2个月内的单据!请检查日期!");
								return ;
							}
							
						}
				 var export_url = '/dealer/shipDealerCashBackAmountInfoExcel?' + $("#basic_validate").serialize()+"&dealer_channel=1";
                window.open(export_url);
				
				
			});
			
			
			$('#page_jump').bind('click', function(){
				
				 var page_index = $('#page_input').val();
				 var total_page = $('#total_page').text();
				
				 var curr_page = $('#curr_page_index').text();
				 
					
				 if (page_index == ''||page_index == undefined||page_index == null) {
	                    page_index = curr_page;
	                }
				 
				 if(parseInt(page_index) <= 0 || parseInt(page_index) > parseInt(total_page)  ){
					 page_index =1;
				 }
				 
				 
				
								
					 DealerCashBackAmountPage.Search(page_index);
				
								
				
			});
			
			
            $(".first,.previous,.last,.next").bind('click', function () {
                if ($(this).hasClass('ui-state-disabled')) {
                    return false;
                }

                var page_index = $(this).attr('page_index');
                if (page_index == undefined) {
                    page_index = 1;
                }
                
              		
					 DealerCashBackAmountPage.Search(page_index);
				
							
            });
		},
		
   
		'Search': function (page_index) {
			var startdate	= $('#start_date').val();
			var enddate	= $('#end_date').val();
			
				if(startdate ==""){
					alert("开始日期不能为空！！！");
					return ;
				}
			   			
				if(enddate ==""){
					alert("结束日期不能为空！！！");
					return ;
				}
				
				var startdates = startdate.split('-');
				var enddates = enddate.split('-');

				startdate = startdates[1] + '/' + startdates[2].split(" ")[0] + '/' + startdates[0]+" "+startdates[2].split(" ")[1] ;
						
				enddate = enddates[1] + '/' + enddates[2].split(" ")[0] + '/' + enddates[0]+" " +enddates[2].split(" ")[1];
                //alert(startdates);
				//alert(startdate);
				
				// MM/dd/yyyy HH:mm:ss
				// alert(Date.parse(startdate));
				 //alert(Date.parse(enddate));
				 
				// var b = (Date.parse(enddate) - Date.parse(startdate)) / ( 3600 * 1000);
				// alert(b);
				 var a = Date.parse(enddate) - Date.parse(startdate) ;
				
				 if(a < 0){
						alert("结束时间不能早于开始时间,请检查!");
						return ;
					}
            var condition = $("#basic_validate").serialize();
            condition += "&pageSize=20&index="+page_index+"&dealer_channel=1";

            $.ajax({
                type: 'post',
                url: '/AjaxService/center/dealer/queryDealerCashBackAmountByPara',
                data: condition,
                dataType: 'json',
                async: false,
                success: function (data) {
                	DealerCashBackAmountPage.BindTable(data.Result, page_index);
                	DealerCashBackAmountPage.SetPageIndex(data.Result.totalPage, data.Result.totalCount, page_index);


                },
                error: function (e, err_name, err_text) {
                    alert(err_text);
                }
            });

        },
        
        'AmountUpdate': function () {
        	var amount = $('#amount').val();
        	var dealer_id = $('#dealer_id1').val();
        	if(dealer_id ==''){
        		
        		alert('请输入经销商编号');
        		return;
        		
        	}
        	
        	if(isNaN(amount)){
        		alert("请输入一个正确金额!");
        		return;
        	}
        	
        	if(parseFloat(amount)<=0){
        		alert("请输入一个大于零的金额!");
        		return;
        	}
        	
        	if(!confirm("确认调整此经销商的金额?请慎重选择!!!")){
    			return;
    		}
        	
            var condition = $("#basic_validate1").serialize();
           
            condition += "&dealer_channel=1"
            $.ajax({
                type: 'post',
                url: '/AjaxService/center/dealer/dealerCashBackAmountUpdate',
                data: condition,
                dataType: 'json',
                async: false,
                success: function (data) {
                	
                	 if (data.IsSuccess == 0) {
	                        alert(data.ErrorMsg);
	                        return;
	                    } else {
	                       //$('#basic_validate').submit();
	                       alert("金额更新成功!");
	                    }

                },
                error: function (e, err_name, err_text) {
                    alert(err_text);
                }
            });

        },
        
		'BindTable': function(result,page_index){
			lst_dealer_amount = result.datas;
			if(lst_dealer_amount.length == 0){				
				$('#search_result tbody').html('');
				var msg ="<tr><td colspan='10' style='text-align:center'>暂无数据!</td></tr>";				
				$('#search_result tbody').append(msg);	
				return;							
			};
			var html = '';
			for(var index in lst_dealer_amount){
				var dealer_amount_en = lst_dealer_amount[index];
				var tr_html = "<tr>";
				tr_html += "<td>" + dealer_amount_en.dealer_id+"</td>";
				tr_html += "<td>" + dealer_amount_en.dealer_name+"</td>";
				tr_html += "<td>" + DealerCashBackAmountPage.ConvertAmountKind(dealer_amount_en.amount_kind)+"</td>";
				tr_html += "<td>" +  DealerCashBackAmountPage.ConvertAmountType(dealer_amount_en.amount_type) + "</td>"
				tr_html += "<td>" + dealer_amount_en.begin_amount + "</td>"
				tr_html += "<td>" + dealer_amount_en.amount + "</td>"
				tr_html += "<td>" + dealer_amount_en.end_amount + "</td>"
				tr_html += "<td>" + DealerCashBackAmountPage.ConvertStrNull(dealer_amount_en.order_id)+"</td>";
				tr_html += "<td>" + DealerCashBackAmountPage.ConvertStrNull(dealer_amount_en.remark)+"</td>";
				tr_html += "<td>" + dealer_amount_en.create_date + "</td>"		
				tr_html += "</tr>";
				html += tr_html;
			} 
			$('#search_result tbody').html('');
			$('#search_result tbody').append(html);
			$('#search_result').attr('page_index', page_index);

		},
		
		'SetPageIndex': function (total_page, total_count, page_index) {
            $('#total_count').text(total_count);
            $('#total_page').text(total_page);
            $('#curr_page_index').text(page_index);
            page_index = parseInt(page_index);
            total_count =parseInt(total_count);
			
			if(total_page == 0){
				$('#paging .last').addClass('ui-state-disabled');
				$('#paging .next').addClass('ui-state-disabled');
				$('#paging .first').addClass('ui-state-disabled');
				$('#paging .previous').addClass('ui-state-disabled');
				return;
			}
            if (page_index == 1) {
                $('#paging .first').addClass('ui-state-disabled');
                $('#paging .previous').addClass('ui-state-disabled');
                $('#paging .first').attr('page_index', 1);
                $('#paging .previous').attr('page_index', 1);
            }
            else {
                $('#paging .first').removeClass('ui-state-disabled');
                $('#paging .previous').removeClass('ui-state-disabled');
                $('#paging .first').attr('page_index', 1);
                $('#paging .previous').attr('page_index', page_index - 1);
            }

            if (total_page == page_index) {
                $('#paging .last').addClass('ui-state-disabled');
                $('#paging .next').addClass('ui-state-disabled');
                $('#paging .last').attr('page_index', total_page);
                $('#paging .next').attr('page_index', total_page);
            }
            else {
                $('#paging .last').removeClass('ui-state-disabled');
                $('#paging .next').removeClass('ui-state-disabled');
                $('#paging .last').attr('page_index', total_page);
                $('#paging .next').attr('page_index', page_index + 1);
            }

        },

		'ConvertStrNull':function(obj){
			
			if(obj == null){
				return '';
			}
			else{
				return obj;
			}
		},
		
		'ConvertAmountKind':function(obj){
			if(obj == '1'){
				return '增加';
			}else if(obj =='2'){
				return '减少';
			}
		} ,		
		
		'ConvertAmountType':function(obj){
			if(obj == '11'){
				return '管理员增加';
			}else if(obj =='12'){
				return '订单提成';
			}else if(obj =='13'){
				return '充值';
			
			}
			else if(obj =='15'){
				return "订单取消余额退回";
			}else if(obj =='16'){
				return "退货退款";
			}
			else if(obj =='21'){
				return '管理员减少';
			}else if(obj =='22'){
				return '提现';
			}
			else if(obj =='24'){
				return '订单支付';
			}
		} ,		
		
};


$(document).ready(function(){
	DealerCashBackAmountPage.BindEvent();
});

	
</script>
</block>